<template>
    <div class="list">
        <div class="header-info">
            <p>用户管理</p>
            <el-button type="primary" @click="add_click()">添加</el-button>
        </div>
        <my-list ref="list" url="/admin-user/list" @param="preload" @loaded="procData"
                 :page-size="pageSize" :store="true"
                 style="width: 100%;margin-top:20px;">
            <el-table-column type="index" clign="center" width="50"></el-table-column>
            <el-table-column label="名称" align="center">
                <template slot-scope="scope">
                    <div class="link" @click="link(scope.row)">{{scope.row.name}}</div>
                </template>
            </el-table-column>
            <el-table-column label="登录名" align="center" prop="loginName">
            </el-table-column>
            <el-table-column label="手机号" align="center" prop="mobile">
            </el-table-column>
            <el-table-column align="center" label="管理员">
                <template slot-scope="scope">
                    <el-tag type="success" v-if="scope.row.needValidateCode">管理员</el-tag>
                    <el-tag v-else>普通用户</el-tag>
                </template>
            </el-table-column>

            <el-table-column align="center" label="创建时间" prop="createAt"></el-table-column>
            <el-table-column label="操作" align="center" width="180">
                <template slot-scope="scope">
                    <el-button @click="delete_click(scope.row)" size="small">
                        删除
                    </el-button>
                </template>
            </el-table-column>


            <template #query="scope">
                <kv label="名称">
                    <el-input v-model="scope.query.name"></el-input>
                </kv>
            </template>
        </my-list>
    </div>
</template>
<style scoped>
</style>
<script>
    /**
     * Created by CodeGenerator
     */
    export default {
        components: {},
        data() {
            return {
                pageSize: 10,
            };
        },
        mounted() {
            this.loadData();
        },
        methods: {
            link(row) {
                this.$router.push("/admin-user/edit/" + row.id)
            },
            //处理请求参数
            preload(param) {
                //添加查询参数，修改分页参数等。
                //param.type = this.$route.params.type
            },
            //处理列表的数据
            procData(res) {
                res.data.data.forEach(it => {
                    //如果是组合实体，设置 it.id=...

                });
            },
            //查询
            loadData(pageNumber) {
                this.$refs.list.loadData(pageNumber);
            },
            add_click() {
                this.$router.push("/admin-user/add")
            },
            edit_click(row) {
                //记录上次点击行
                var rowId = row.id;
                this.$refs.list.setLastRow(row);
                this.$router.push("/admin-user/edit/" + rowId)
            },
            delete_click(row) {
                var rowId = row.id;
                var rowName = row.name;
                jv.confirm('确认删除 ' + rowName + ' 吗？').then(res => {
                    this.$http.post("/admin-user/delete/" + rowId).then(res => {
                        this.loadData();
                    })
                });
            }
        }
    }
</script>